package com.spl.mcm.models.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MCMSQLiteHelper extends SQLiteOpenHelper{
	
	public static final String TABLE_INTERCEPTS_NAME = "Intercepts";
	public static final String TABLE_INTERCEPTS_COLUMN_ID = "_id";
	public static final String TABLE_INTERCEPTS_COLUMN_NAME = "name";
	public static final String TABLE_INTERCEPTS_COLUMN_NUMBER = "number";
	public static final String TABLE_INTERCEPTS_COLUMN_INTERCEP_WAY = "way";
	public static final String TABLE_INTERCEPTS_COLUMN_INTERCEP_TYPE = "type";
	private static final String TABLE_INTERCEPTS_CREATE = "CREATE TABLE " + TABLE_INTERCEPTS_NAME
														+ "(" + TABLE_INTERCEPTS_COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
														+ TABLE_INTERCEPTS_COLUMN_NAME + " TEXT,"
														+ TABLE_INTERCEPTS_COLUMN_NUMBER + " TEXT,"
														+ TABLE_INTERCEPTS_COLUMN_INTERCEP_WAY + "TEXT,"
														+ TABLE_INTERCEPTS_COLUMN_INTERCEP_TYPE + "TEXT);";
	
	public static final String TABLE_SMSRECORDING_NAME = "SMSRecordings";
	public static final String TABLE_SMSRECORDING_COLUMN_ID = "_id";
	public static final String TABLE_SMSRECORDING_COLUMN_INTERCEPTID = "interceptid";
	public static final String TABLE_SMSRECORDING_COLUMN_CONTENT = "content";
	public static final String TABLE_SMSRECORDING_COLUMN_TIME = "time";
	private static final String TABLE_SMSRECORDING_CREATE = "CREATE TABLE " + TABLE_SMSRECORDING_NAME
															+ "(" + TABLE_SMSRECORDING_COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
															+ TABLE_SMSRECORDING_COLUMN_INTERCEPTID + " INTEGER,"
															+ TABLE_SMSRECORDING_COLUMN_CONTENT + " TEXT,"
															+ TABLE_SMSRECORDING_COLUMN_TIME + " TEXT);";
	
	public static final String TABLE_CALLRECORDING_NAME = "CallRecordings";
	public static final String TABLE_CALLRECORDING_COLUMN_id = "_id";
	public static final String TABLE_CALLRECORDING_COLUMN_INTERCEPTID = "interceptid";
	public static final String TABLE_CALLRECORDING_COLUMN_TIME = "time";
	private static final String TABLE_CALLRECORDING_CREATE = "CREATE TABLE " + TABLE_CALLRECORDING_NAME
															+ "(" + TABLE_CALLRECORDING_COLUMN_id + " INTEGER PRIMARY KEY AUTOINCREMENT ,"
															+ TABLE_CALLRECORDING_COLUMN_INTERCEPTID + " INTEGER,"
															+ TABLE_SMSRECORDING_COLUMN_TIME + " TEXT);";
	
	
	
	public MCMSQLiteHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		Log.i("SUMPRO", "Create Table:" + TABLE_INTERCEPTS_CREATE);
		db.execSQL(TABLE_INTERCEPTS_CREATE);
		
		Log.i("SUMPRO", "Create Table:" + TABLE_CALLRECORDING_CREATE);
		db.execSQL(TABLE_CALLRECORDING_CREATE);
		
		Log.i("SUMPRO", "Create Table:" + TABLE_SMSRECORDING_CREATE);
		db.execSQL(TABLE_SMSRECORDING_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w("SUMPRO",
		        "Upgrading database from version " + oldVersion + " to "
		            + newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_INTERCEPTS_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_SMSRECORDING_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_CALLRECORDING_NAME);
		onCreate(db);
	}

}
